package com.liwenfeng.diancanspringboot.mapper;

import com.github.pagehelper.Page;
import com.liwenfeng.diancanspringboot.annotation.AutoFill;
import com.liwenfeng.diancanspringboot.common.enumeration.OperationType;
import com.liwenfeng.diancanspringboot.pojo.dto.DishPageQueryDTO;
import com.liwenfeng.diancanspringboot.pojo.entity.Dish;
import com.liwenfeng.diancanspringboot.pojo.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    @Select("select count(id) from dish where category_id = #{id}")
    Integer countByCategoryId(Long id);

    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);

    void deleteByIds(List<Long> ids);

    @AutoFill(OperationType.INSERT)
    @Insert("insert into dish(name, category_id, price, image, description, status, create_time, update_time, create_user, update_user) values(#{name}, #{categoryId}, #{price}, #{image}, #{description}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(Dish dish);

    @Select("select * from dish where category_id = #{categoryId}")
    List<Dish> listByCategoryId(long categoryId);

    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);

    List<Dish> list(Dish dish);

//    @Select("select count(id) from dish where id in (#{ids}) and status = #{status}")
    int countByStatus(List<Long> ids, int status);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);

    @Select("select * from dish where name = #{name}")
    Dish getByName(String name);
}
